<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8" />
        <title>23_定时器-取消单次定时器</title>
    </head>
    <body>
        <button>取消单次定时器</button>


        <script>
            // setTimeout的返回值是一个id值  唯一的 默认从1开始依次递增

            var timer = setTimeout(function(){
                console.log('祝福有情人');
            },5000);


            var btn = document.querySelector('button');
            btn.onclick = function(){
                clearTimeout(timer);
            }


        </script>
    </body>
</html>